	$(function(){
 				$('#dg').datagrid({    
   				 url:'admin/role/listRows', 
   				 toolbar:'#tb',
   				 fit:true, 
   				 border:false,
   				 rownumbers:true,
   				 singleSelect:false,
   				 checkOnSelect:true,
   				 autoRowHeight:false,
   				 loadMsg:'加载中，请稍等...',
   				 striped:true,//显示斑马线
   				 idField:'id',//翻页时记住前面选的
   				 pagination:true,//显示底部分页工具栏
   				 pageSize:10,
   				 pageList:[10,20,30,40,50],
  				 columns:[[
  						 { field:'ck',checkbox:true },
		       			 {field:'id',title:'ID',width:'10%',sortable:true,hidden:true},    
		       			 {field:'roleName',title:'账号角色',width:'30%'},    
		       			 {field:'description',title:'描述',width:'55%'}
  		  				]]    
					}); 
 			});
 			
	var url = "";
	// 新增对话框
    function add(){
//    	show();
    	var parent = $('#iframeid', window.parent.document);
//    	console.info(parent.$);
    	console.info(parent);
    	$("#fm").form('clear');
    	 //window.parent.
    	 /*$('#dlg').dialog({
            title: '添加角色信息',
            width:400,
            height:280,
            iconCls: 'icon-add',               //弹出框图标
            modal: true
        });*/
    	console.info(parent.$('#dlg'));
    	$('#dlg').dialog("open").dialog("setTitle","添加角色信息");  
    	url = 'admin/role/save';
    };

	// 修改对话框
    function edit(){
		var rows=$("#dg").datagrid('getSelections');
		if(rows.length !=1){
			$.messager.alert('系统提示','请选择一条要编辑的数据！');
			return;
		}
		var row=rows[0];
		$("#dlg").dialog("open").dialog("setTitle","修改用户信息");
		$("#fm").form("load",row);
		url = 'admin/role/edit?id='+row.id;
	}
	
    // 关闭添加修改对话框
    function closeDialog(){
    	$("#fm").form('clear');
    	$("#dlg").dialog("close");
    }

	
 /**
 *删除
 */
 function del(){
 	var row = $('#dg').datagrid('getSelected');
		$.messager.confirm('确认','您确认想要删除记录吗？',function(r){    
				if (r){    
					$.ajax({
						type:'POST',
						url:'admin/role/deleteById',
						data:{id:row.id},
						dataType:'json',
						success:function(data){
								if(data && data.success){
										$.messager.show({
												title:'提示',
												msg:data.message
										});
										$('#dg').datagrid('unselectAll'); 
										$('#dg').datagrid('reload'); 
								}else{
										$.messager.alert('提示',data.message);
								}
							},
						});
					}    
				}); 
 			} 
/**
 * 验证
 */ 
 
 /*function a(){
	 var validate = $("#fm").validate({
		 rules:{
			           roleName:{
			             required:true
			           }
		 },
		 messages:{
			 roleName:{
	            required:"必填"
	          }
		 }
	 });
 }*/
 			
 function saveOrEdit(){
	 $.ajax({
			type:'POST',
			url:url,
			data:$('#fm').serialize(),
			dataType:'json',
			success:function(data){
					if(data && data.success){
								$('#dlg').dialog('close');
								$.messager.show({
									title:'提示',
									msg:data.message
								});
								$('#dg').datagrid('unselectAll'); 
								$('#dg').datagrid('reload'); 
					}else{
							$.messager.alert('提示',data.message);
					}
			},
			error:function(data){
				$.messager.alert('提示',data.message);
			}
	 });
 }
 /**
  * 
  */
 function roleMenu(){
	 var rows=$("#dg").datagrid('getSelections');
	if(rows.length !=1){
		$.messager.alert('系统提示','请选择一种角色类型!');
		return;
	}
	 $('#dlg-rolemenu').dialog("open").dialog("setTitle","分配菜单信息");  
	 $('#tt').tree('reload'); 
 }
 
 function saveOrEditAuthority(){
	 var menuSelected = $('#tt').tree('getChecked');
	 var roleSelected=$("#dg").datagrid('getSelections');
	 var params = {};
	 params.menus = menuSelected;
	 params.role = roleSelected[0];
	 $.ajax({
		 	url:'admin/role/saveOrEditAuthority',
			type:'POST',
			contentType: "application/json; charset=utf-8",
			dataType:'json',
			data:JSON.stringify(params),
			success:function(result){
					if(result && result.success){
						$.messager.show({
							title:'提示',
							msg:'恭喜你,保存成功!'
						});
						$('#dlg-rolemenu').dialog('close');
					}else{
							$.messager.alert('提示',data.message);
					}
			}
	 });
 }
